{
  "name": "{{ item }}-network",
  "x-type": "hlfv1",
  "version": "1.0.0",
  "client": {
    "organization": "{{ item }}",
    "connection": {
      "timeout": {
        "peer": { "endorser": "300", "eventHub": "300", "eventReg": "300"},
        "orderer": "300"
      }
    }
  },
  "channels": {
    "firstchannel": {
      "orderers": [
{% for orderer in allorderers %}
        "{{ orderer.name }}"{{ '' if loop.last else ',' }}
{% endfor %}
      ],
      "peers": {
{% for peer in allpeers %}
        "{{ peer.name }}": {
          "endorsingPeer": true, "chaincodeQuery": true, "eventSource": true
        }{{ '' if loop.last else ',' }}
{% endfor %}
      }
    }
  },
  "organizations": {
{% for org in allorgs %}
    "{{ org }}": {
      "mspid": "{{ org }}",
      "peers": [
{% for peer in allpeers|selectattr('org', 'equalto', org)|list %}
        "{{ peer.name }}"{{ '' if loop.last else ',' }}
{% endfor %}
      ],
      "certificateAuthorities": [
{% for ca in allcas|selectattr('org', 'equalto', org)|list %}
        "{{ ca.name }}"{{ '' if loop.last else ',' }}
{% endfor %}
      ]
    }{{ '' if loop.last else ',' }}
{% endfor %}
  },
  "orderers": {
{% for orderer in allorderers %}
    "{{ orderer.name }}": {
      "url": "{{ orderer.name }}:7050",
      "grpcOptions": {
        "ssl-target-name-override": "{{ orderer.name }}"
      },
      "tlsCACerts": {
        "pem": "{{ '/fabric/keyfiles/'+orderer.org+'/orderers/'+orderer.name+'.'+orderer.org+'/tls/ca.crt' }}"
      }
    }{{ '' if loop.last else ',' }}
{% endfor %}
  },
  "peers": {
{% for peer in allpeers %}
    "{{ peer.name }}": {
      "url": "{{ peer.name }}:7051",
      "eventUrl": "{{ peer.name }}:7053",
      "grpcOptions": {
        "ssl-target-name-override": "{{ peer.name }}"
      },
      "tlsCACerts": {
        "pem": "{{ '/fabric/keyfiles/'+peer.org+'/tlsca/tlsca.'+peer.org+'-cert.pem' }}"
      }
    }{{ '' if loop.last else ',' }}
{% endfor %}
  },
  "certificateAuthorities": {
{% for ca in allcas|selectattr('org', 'equalto', item)|list %}
    "{{ ca.name }}": {
      "url": "{{ tls|ternary('https','http') }}://{{ k8shosts[ca.name] }}:{{ k8sports[ca.name+':7054'] }}",
      "caName": "{{ ca.name }}",
      "httpOptions": {"verify": false},
      "tlsCACerts": {
        "path": "{{ '/fabric/keyfiles/'+ca.org+'/tlsca/tlsca.'+ca.org+'-cert.pem' }}"
      }
    }{{ '' if loop.last else ',' }}
{% endfor %}
  },
  "entityMatchers": {
    "orderer": [
{% for orderer in allorderers %}
      { "mappedHost": "{{ orderer.name }}",
        "pattern": "(\\w*){{ orderer.name }}(\\w*)",
        "sslTargetOverrideUrlSubstitutionExp": "{{ orderer.name }}",
        "urlSubstitutionExp": "{{ k8shosts[orderer.name] }}:{{ k8sports[orderer.name+':7050'] }}"
      }{{ '' if loop.last else ',' }}
{% endfor %}
    ],
    "peer": [
{% for peer in allpeers %}
      { "mappedHost": "{{ peer.name }}",
        "pattern": "(\\w*){{ peer.name }}(\\w*)",
        "sslTargetOverrideUrlSubstitutionExp": "{{ peer.name }}",
        "urlSubstitutionExp": "{{ k8shosts[peer.name] }}:{{ k8sports[peer.name+':7051'] }}",
        "eventUrlSubstitutionExp": "{{ k8shosts[peer.name] }}:{{ k8sports[peer.name+':7053'] }}"
      }{{ '' if loop.last else ',' }}
{% endfor %}
    ]
  }
}
